home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / wnos / wn941101 / nrdump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-10  |  3.0 KB  |  114 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "config.h"
  4. #ifdef NETROM
  5. #include "mbuf.h"
  6. #include "netrom.h"
  7. #include "nr4.h"
  8. #include "trace.h"
  9.  
  10. /* Display NET/ROM network and transport headers */
  11. void
  12. netrom_dump(fp,bpp,check)
  13. FILE *fp;
  14. struct mbuf **bpp;
  15. int check;
  16. {
  17.     char src[AXALEN], dest[AXALEN], tmp[AXBUF], tmp1[AXBUF], thdr[NR4MINHDR];
  18.     char space[] = "         ";
  19.     int i;
  20.  
  21.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  22.         return;
  23.     /* See if it is a routing broadcast */
  24.     if(uchar(*(*bpp)->data) == NR3NODESIG) {
  25.         (void)PULLCHAR(bpp);        /* Signature */
  26.         pullup(bpp,tmp,ALEN);
  27.         tmp[ALEN] = '\0';
  28.         trprintf(fp,"NET/ROM Routing: %s\n",tmp);
  29.         for(i = 0;i < NRDESTPERPACK;i++) {
  30.             if (pullup(bpp,src,AXALEN) < AXALEN)
  31.                 break;
  32.             trprintf(fp,"%20s",pax25(tmp,src));
  33.             pullup(bpp,tmp,ALEN);
  34.             tmp[ALEN] = '\0';
  35.             trprintf(fp,"%8s",tmp);
  36.             pullup(bpp,src,AXALEN);
  37.             trprintf(fp,"%16s",pax25(tmp,src));
  38.             tmp[0] = PULLCHAR(bpp);
  39.             trprintf(fp,"%7u\n",uchar(tmp[0]));
  40.         }
  41.         return;
  42.     }
  43.     /* Decode network layer */
  44.     pullup(bpp,src,AXALEN);
  45.     pullup(bpp,dest,AXALEN);
  46.     i = PULLCHAR(bpp);
  47.  
  48.     trprintf(fp,"NET/ROM: %s->%s ttl %d\n",
  49.         pax25(tmp,src),pax25(tmp1,dest),i);
  50.  
  51.     /* Read first five bytes of "transport" header */
  52.     pullup(bpp,thdr,NR4MINHDR);
  53.     switch(thdr[4] & NR4OPCODE){
  54.      case NR4OPPID:    /* network PID extension */
  55.         if (thdr[0] == NRPROTO_IP && thdr[1] == NRPROTO_IP) {
  56.              ip_dump(fp,bpp,check) ;
  57.             return;
  58.         }
  59.          else
  60.             trprintf(fp,"%sprotocol family %x, proto %x",
  61.                 space,uchar(thdr[0]),uchar(thdr[1])) ;
  62.          break ;
  63.     case NR4OPCONRQ:    /* Connect request */
  64.         i = PULLCHAR(bpp);
  65.         pullup(bpp,src,AXALEN);
  66.         pullup(bpp,dest,AXALEN);
  67.         trprintf(fp,"%sconn rqst: ckt %d/%d wnd %d %s@%s",
  68.             space,
  69.             uchar(thdr[0]), uchar(thdr[1]),i,
  70.             pax25(tmp,src),pax25(tmp1,dest));
  71.         break;
  72.     case NR4OPCONAK:    /* Connect acknowledgement */
  73.         i = PULLCHAR(bpp);
  74.         trprintf(fp,"%sconn ack: ur ckt %d/%d my ckt %d/%d wnd %d",
  75.             space,
  76.             uchar(thdr[0]), uchar(thdr[1]),
  77.             uchar(thdr[2]), uchar(thdr[3]), i);
  78.         break;
  79.     case NR4OPDISRQ:    /* Disconnect request */
  80.         trprintf(fp,"%sdisc: ckt %d/%d",
  81.             space,
  82.             uchar(thdr[0]),uchar(thdr[1]));
  83.         break;
  84.     case NR4OPDISAK:    /* Disconnect acknowledgement */
  85.         trprintf(fp,"%sdisc ack: ckt %d/%d",
  86.             space,
  87.             uchar(thdr[0]),uchar(thdr[1]));
  88.         break;
  89.     case NR4OPINFO:    /* Information (data) */
  90.         trprintf(fp,"%sinfo: ckt %d/%d txseq %d rxseq %d",
  91.             space,
  92.             uchar(thdr[0]), uchar(thdr[1]),
  93.             uchar(thdr[2]), uchar(thdr[3]));
  94.         break;
  95.     case NR4OPACK:    /* Information acknowledgement */
  96.         trprintf(fp,"%sinfo ack: ckt %d/%d txseq %d rxseq %d",
  97.             space,
  98.             uchar(thdr[0]),uchar(thdr[1]),
  99.             uchar(thdr[2]), uchar(thdr[3]));
  100.         break;
  101.     default:
  102.         trprintf(fp,"%sunknown transport type %d",space,thdr[4] & 0x0f) ;
  103.         break;
  104.     }
  105.     if(thdr[4] & NR4CHOKE)
  106.         trprintf(fp," CHOKE");
  107.     if(thdr[4] & NR4NAK)
  108.         trprintf(fp," NAK");
  109.     if(thdr[4] & NR4MORE)
  110.         trprintf(fp," MORE");
  111.     trprintf(fp,"\n");
  112. }
  113.  
  114. #endif /* NETROM */